package top.lanscarlos.ashcraft.service;

import com.sun.istack.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.lang.Nullable;
import org.springframework.stereotype.Service;
import top.lanscarlos.ashcraft.pojo.LogInfo;
import top.lanscarlos.ashcraft.pojo.User;
import top.lanscarlos.ashcraft.repository.UserRepository;

/**
 * Ashcraft
 * top.lanscarlos.ashcraft.service
 *
 * @author Lanscarlos
 * @since 2022-05-25 14:26
 */
@Service
public class UserService {

    @Autowired
    private UserRepository repository;

    /**
     * 注册
     *
     * @return 注册成功返回对象 反之 null
     * */
    @Nullable
    public User register(
            @NotNull String name,
            @NotNull String password,
            @Nullable String avatar,
            @Nullable String signature,
            int gender,
            @Nullable String address,
            @NotNull String phone,
            double money
    ) {
        User user = new User(name, password, avatar, signature, gender, 0.0, address, phone);
        user.setMoney(money);
        return repository.insert(user) ? user : null;
    }

}
